﻿using System;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;
using PD.DataAccess;

namespace PD.Web
{
    /// <summary>
    /// The default master page for all pages.
    /// </summary>
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.ProviderUserKey().HasValue)
            {
                MenuItem myTasks = this.NavigationMenu.Items[this.NavigationMenu.Items.Count - 1];
                myTasks.NavigateUrl = this.Page.ResolveUrl("~/Tasks/List.aspx?AssignedTo=" + HttpContext.Current.ProviderUserKey().Value.ToString());
            }

            string[] roles = Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name);
            if (roles.Length > 0)
            {
                Label roleNameLbl = this.HeadLoginView.FindControl("RoleName") as Label;
                roleNameLbl.Visible = true;
                roleNameLbl.Text = string.Format(CultureInfo.CurrentCulture, " ({0})", string.Join(", ", roles));
            }
        }
    }
}
